package com.kehao.leetcode.basic.linkedList;




public class LinkedListSolution3 {

    class ListNode {
        int val;
        ListNode next;
        ListNode() {}
        ListNode(int val) { this.val = val; }
        ListNode(int val, ListNode next) { this.val = val; this.next = next; }
    }

    public ListNode reverseList(ListNode head) {
        ListNode head0 = new ListNode();
        head0.next = null;
        ListNode node = head;
        while (node!=null){
            node = node.next;
            head.next = head0.next;
            head0.next = head;
            head = node;
        }
        return head0.next;
    }
}

